package com.tanhua.dubbo.api.db;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.api.mapper.BlackListMapper;
import com.tanhua.model.db.BlackList;
import com.tanhua.model.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class BlackListApiImpl implements BlackListApi{

    @Autowired
    private BlackListMapper blackListMapper;

    /**
     * 分页查询黑名单列表
     * @param userId
     * @param page
     * @param pageSize
     * @return
     */
    @Override
    public PageResult<BlackList> findPage(Long userId, Long page, Long pageSize) {
        IPage<BlackList> iPage = new Page(page, pageSize);
        blackListMapper.selectPage(iPage, Wrappers.<BlackList>lambdaQuery()
                .eq(BlackList::getUserId, userId));
        return new PageResult(page, pageSize, iPage.getTotal(), iPage.getRecords());
    }

    /**
     * 移除黑名单
     * @param blackUserId
     */
    @Override
    public void removeBlack(Long userId, Long blackUserId) {
        blackListMapper.delete(Wrappers.<BlackList>lambdaQuery()
                .eq(BlackList::getUserId, userId)
                .eq(BlackList::getBlackUserId, blackUserId));
    }
}
